package org.rabbitmq.two;

import com.rabbitmq.client.Channel;
import org.rabbitmq.util.RabbitMQUtil;

import java.util.Scanner;

public class Task01 {

    /**
     * 队列名称
     */
    private final static String QUEUE_NAME = "hello";

    public static void main(String[] args) throws Exception {
        try (Channel channel = RabbitMQUtil.getChannel()) {
            channel.queueDeclare(QUEUE_NAME, false, false, false, null);
            // 从控制台中接收消息
            Scanner scanner = new Scanner(System.in);
            while (scanner.hasNext()) {
                String message = scanner.next();
                channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
                System.out.println("消息发送完成: " + message);
            }
        }
    }
}
